<?php
  PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/post.css\" rel=\"stylesheet\">");
  PageUtil::addVar("title",$post['title']);
  PageUtil::addVar("keywords",$metaKeyword);
  PageUtil::addVar("description",mb_substr(strip_tags($post['content']),0,120));
?>
<!-- tiny mce -->
<script src="<?php echo $jspath."/tinymce/tinymce.min.js"; ?>"></script>
<script>
  tinymce.init({
    selector: "#elm1",
    theme: "modern",
    font_size_style_values : "xx-small,x-small,small,medium,large,x-large,xx-large",
    height: 200,
    menubar : false,
    plugins: [
      "advlist autolink  image lists charmap print preview hr anchor pagebreak spellchecker",
      "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
      "save table contextmenu directionality emoticons template paste textcolor importcss"
    ],
    add_unload_trigger: false,
    toolbar: "insertfile undo redo | bold italic | alignleft aligncenter alignright alignjustify | forecolor fullpage backcolor  preview  ",
    image_advtab: true,
    style_formats: [
      {title: 'Bold text', format: 'h1'},
      {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
      {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
      {title: 'Example 1', inline: 'span', classes: 'example1'},
      {title: 'Example 2', inline: 'span', classes: 'example2'},
      {title: 'Table styles'},
      {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
    
  });
</script>
<!-- end tiny mce -->
<!-- style image galery box swipe  -->
  <link href="<?php echo $jspath.'/photoswipe/photoswipe.css'; ?>" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="<?php echo $jspath.'/photoswipe/lib/klass.min.js'; ?>"></script>
  <script type="text/javascript" src="<?php echo $jspath.'/photoswipe/code.photoswipe.jquery-3.0.5.min.js'; ?>"></script>
  <script type="text/javascript">
    (function(window, $, PhotoSwipe){
      $(document).ready(function(){
        var options = {
          imageScaleMethod: "fitNoUpscale"
        };
        $(".gallery a").photoSwipe(options);
      });
    }(window, window.jQuery, window.Code.PhotoSwipe));
  </script>
<!-- end -->

<script type="text/javascript">
$(function (){
  $('.imggroup').mouseover(function() {
    var src = $(this).parent("a").data("image");
    var src2 =  $(this).parent("a").attr("href");
    var show = $(this).attr("class");
    $('#large_image').html('<div class="gallery"><a href="'+src2+'"><img src="'+src+'" alt="หมวดหมู่ : ภาพหน้าปก" class="img-responsive"/></a></div>');
    (function(window, $, PhotoSwipe){
      $(document).ready(function(){
        var options = {
          imageScaleMethod: "fitNoUpscale"
        };
        $(".gallery a").photoSwipe(options);
      });
    }(window, window.jQuery, window.Code.PhotoSwipe));
  });
});
</script>

<section class="content_block col-xs-12 col-sm-12 col-md-12 col-lg-12">
  <nav class="breadcrumb">
    <?php echo $breadcrumb;?>
  </nav>
  <section class="row">
    <section class="post_title col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <a href="<?php echo base_url("post/view/".$post['url']);?>">
        <h1>
          <?php echo $post['title'];?>

        </h1>
      </a>
    </section>
  </section>

  <section class="row">
        <?php
          if(!empty($first_images)){
        ?>
                <div id="large_image" class="col-xs-7 col-sm-7 col-md-7 col-lg-7">
                  <div class="gallery"><!-- use jqly image-->
                    <a href="<?php echo base_url($first_images['filepath']);?>"><img src="<?php echo base_url($first_images['medium']);?>" alt="<?php echo $post['title'];?>" class="img-responsive"/></a>
                  </div>
                </div>
          <?php
          }else{
            echo "<img src=\"".$imagepath."/not_available.jpg\"/>";
          }
        ?>

        <div id="group" class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
          <div class="gallery" >
            <?php if(!empty($images)) {
              foreach($images as $image):
                foreach ($image as $imageItem) {
                  ?>
                <a href="<?php echo base_url($imageItem['filepath']);?>" data-image="<?php echo base_url($imageItem["medium"]); ?>" class="margin-bottom col-xs-4 col-sm-4 col-md-4 col-lg-4"><img src="<?php echo base_url($imageItem['small']);?>"  class="imggroup img-responsive" alt="<?php echo $post['title'];?> : สภาพภายนอก"/> </a>
                  <?php
                }
              endforeach;
            }
            ?>
          </div>
        </div>
  </section>

  <section class="row">
    <section class="owner-post-option  col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <div class="pull-left">
        <div class="fb-like" data-href="<?php echo base_url("post/view/".$post['url']);?>" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
      </div>
      <div class="pull-right">
        <button type="button" class="btn btn-primary btn-xs btn-toolbar dropdown-toggle" data-toggle="dropdown">
          จัดการประกาศ
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li><a href="<?php echo base_url('post/updatepost/'.$post['id']);?>" title="ดันประกาศขึ้นหน้าแรก">ดันประกาศขึ้นหน้าแรก</a></li>
          <li><a href="<?php echo base_url('post/add/'.$post['id']);?>" title="แก้ไขประกาศ">แก้ไขประกาศ</a></li>
          <li class="divider"></li>
          <li><a href="<?php echo base_url('post/del/'.$post['id']);?>" title="ลบประกาศ">ลบประกาศ</a></li>
        </ul>
      </div>
    </section>
  </section>
  <section class="row">
    <section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <h2>คำอธิบาย</h2>
      <article>
          <?php echo $post['content'];?>
      </article>
    </section>
  </section>

  <div class="row comment-box">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <h2>แสดงความคิดเห็น <span class="badge"><?php echo $comment_count;?></span></h2>
    </div>
    <?php
    if(!empty($comments)){
      foreach ($comments as $keyComment => $comment) {
      ?>
      <!-- Start Comment Block -->
      <div class="panel-body">
        <div class="row">
          <div class="col-xs-2 col-md-1">
            <img src="http://placehold.it/80" class="img-rounded img-responsive" alt="" /></div>
          <div class="col-xs-10 col-md-11">
            <div>
              <a href="<?php echo base_url("post/view/".$post['url']);?>">
                <?php echo $comment["title"]; ?>
              </a>
              <small>
                <div class="mic-info">
                  โดย: <a href="<?php echo base_url("post/user/".$comment['username']);?>"><?php echo $comment["first_name"]." ".$comment["last_name"]; ?></a> (<?php echo Util::blindIP($comment["usr_ip"]); ?>) เมื่อ <?php echo $comment["cr_date"]; ?>
                </div>
              </small>
            </div>
              <div class="comment-text">
                <p>
                  <?php echo $comment["content"]; ?>
                </p>
              </div>
              <?php
              if($this->ion_auth->in_group("admin")){
                ?>
                <div class="action">
                    <button type="button" class="btn btn-primary btn-xs" title="Edit">
                        <span class="glyphicon glyphicon-pencil"></span>
                    </button>
                    <button type="button" class="btn btn-success btn-xs" title="Approved">
                        <span class="glyphicon glyphicon-ok"></span>
                    </button>
                    <button type="button" class="btn btn-danger btn-xs" title="Delete">
                        <span class="glyphicon glyphicon-trash"></span>
                    </button>
                </div>
                <?php
              }

              ?>
              
          </div>
        </div>
      </div>
      <!-- End Comment Block -->
      <?php
      }//End comment foreach
    }else{
      ?>
      <div class="panel-body">
        <div class="panel panel-danger">
          <div class="panel-body text-center">
            <p>ยังไม่มีความเห็น</p>
          </div>
        </div>
      </div>
      <?php
    }
    ?>
  </div>
<?php
if($this->ion_auth->logged_in()){
?>
<div class="row">
    <div class="col-sm-12 col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <form accept-charset="UTF-8" action="<?php echo base_url('comment/reply'); ?>" method="POST">
                        <input name="pos_id" value="<?php echo $post["id"];?>" type="hidden">
                        <input name="type" value="post" type="hidden">
                        <textarea class="form-control counted" name="content" placeholder="Type in your message" rows="5" style="margin-bottom:10px;"></textarea>
                        <h6 class="pull-right" id="counter"></h6>
                        <button class="btn btn-info" type="submit">แสดงความเห็น</button>
                    </form>
                </div>
            </div>
        </div>
  </div>
<?php
}else{
?>
<div class="panel-body">
  <div class="panel panel-danger">
    <div class="panel-heading">
      <h3 class="panel-title">แจ้งเตือน!</h3>
    </div>
    <div class="panel-body text-center">
      <p>ต้องการแสดงความคิดเห็นกรุณาล็อคอิน แต่ถ้ายังไม่ได้สมัครสมาชิกคลิกสมัครสมาชิก</p>
      <a href="<?php echo base_url('user/login'); ?>" ><button type="button" class="btn btn-primary">ล็อคอิน</button></a>
      <a href="<?php echo base_url('user/register'); ?>" ><button type="button" class="btn btn-success" id="button_reg">สมัครสมาชิก</button></a>
    </div>
  </div>
</div>
<?php
}
?>
</section>
